function sxqrcode() {
    var codetext = $('input[name="wechat_qrcode"]').val();
    if (codetext) {
        $("#wechatcode").html("");
        $("#wechatcode").qrcode({
            render: "canvas", //table方式
            width: 30, //宽度
            height: 30, //高度
            text: codetext //任意内容
        });
    }

}

$(document).ready(function ($) {
    sxqrcode();
});


// 上传头像
$('input[name="wechatCode"]').change(function (event) {
    bottlecms.uploadfile({
        elem: this,
        success: function (pic) {
            var loadingobj = bottlecms.loading("识别中…");
            bottlecms.put('', {qrcode: pic}, function (data) {
                bottlecms.log(data)
                loadingobj.close();
                if (data.success == true) {
                    $('input[name="wechat_qrcode"]').val(data.obj);
                    sxqrcode();
                } else {
                    bottlecms.toast(data.msg);
                }
            })
        }
    })
});


var _page = $('.page')

var thisload2 = bottlecms.load({
    elem: $('.infinite-contact2'),
    scroll: $('.infinite-scroll2'),
    done: function (page, next) {
        var src = this.elem.attr("pages-src");
        bottlecms.get(src, {
            page: page
        }, function (data) {
            var lis = [];
            for (var o in data.list) {
                lis.push(contact_apply_template(data.list[o], true))
            }
            next(lis.join(''), lis.length);
        })
    }
})
var thisload3 = bottlecms.load({
    elem: $('.infinite-contact3'),
    scroll: $('.infinite-scroll3'),
    done: function (page, next) {
        var src = this.elem.attr("pages-src");
        bottlecms.get(src, {
            page: page
        }, function (data) {
            var lis = [];
            for (var o in data.list) {
                lis.push(contact_apply_template(data.list[o]))
            }
            next(lis.join(''), lis.length);
        })
    }
})


var tabload = function () {
    setTimeout(function () {
        if ($('.bcui-tab .bcui-tab-content .item.active .infinite-contact1').length > 0) {
            thisload1.init();
        } else if ($('.bcui-tab .bcui-tab-content .item.active .infinite-contact2').length > 0) {
            thisload2.init();
        } else if ($('.bcui-tab .bcui-tab-content .item.active .infinite-contact3').length > 0) {
            thisload3.init();
        }
    }, 100)
}

$(_page).on('click', '.bcui-tab .bcui-tab-title .item', function (event) {
    tabload();
});
tabload();


// 同意
$(_page).on('click', '.bcui-infinite-list .item .js_agree', function (event) {
    var target_id = $(this).attr('data-id')
    var _this = this;
    bottlecms.confirm("确定同意吗？", function () {
        agree_apply_contact_fun(target_id, function () {
            $(_this).parents(".item").attr('status', 1);
        });
    })
});
// 拒绝
$(_page).on('click', '.bcui-infinite-list .item .js_refuse', function (event) {
    var target_id = $(this).attr('data-id');
    var _this = this;
    bottlecms.confirm("确定拒绝吗？", function () {
        refuse_apply_contact_fun(target_id, function () {
            $(_this).parents(".item").attr('status', 2);
        });
    })
});

function checkContact() {
    var wechatid = $("#wechatid").val();
    // var email = $("#email").val();
    var phone = $("#phone").val();
    if (wechatid == undefined || wechatid.length <= 0) {
        bottlecms.toast("请输入微信号");
        return false;
    }
    if (phone == undefined || phone.length != 11) {
        bottlecms.toast("请正确输入联系电话");
        return false;
    }
    $("#form_contact").attr("action", "/m/ajax/center/contact");
}